home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 0292.ZIP / DSI-DCAT.ARC / DSIDCAT.DOC < prev    next >
Text File  |  1985-12-21  |  14KB  |  312 lines

  1. .foDSIdCAT - Olympia                                                Page #
  2. .UJ1
  3. .cw10
  4.  
  5.              DSI dCAT - DISK CATALOG PROGRAM in dBASE III
  6.  
  7.  
  8.                                   by
  9.  
  10.                          P. L. Olympia, Ph.D.
  11.                     Sysop, SMUG RBBS, 301-963-5249
  12.  
  13.  
  14.      Users  of  dBASE II who for years have had to program around  its 
  15. many  limitations are smiling these days - dBASE III has  arrived  and 
  16. with it the computing power that everyone had been clamoring for.   It 
  17. is a tribute to the versatility of dBASE III that it took very  little 
  18. time,  not too mention very little code, for us to convert many of our 
  19. application   programs  and  utilities  from  traditional  programming 
  20. languages  to dBASE III.   Two of our most heavily used programs  that 
  21. we  converted within a week of dBASE III's arrival were an appointment 
  22. calendar  generator (originally written in "C") and a disk  cataloging 
  23. system (originally written in assembler).
  24.  
  25.      This article describes DSI dCAT,  a subset of our disk cataloging 
  26. system that is hereby being released to the public domain. The article 
  27. is also partly a tutorial on the new features of dBASE III.
  28.  
  29.  
  30. DSI dCAT IN A NUTSHELL
  31.  
  32.      The system allows one to maintain a catalog of files contained on 
  33. either  floppy  or  fixed  disks.    Files  contained  on  the  disk's 
  34. subdirectory (excluding the .  and ..  "files") will also be read  and 
  35. cataloged. Since the system was originally conceived to track diskette 
  36. files,  it  is  presently set to handle up to nine subdirectories on  a 
  37. given disk but not subdirectories within subdirectories.   The  system 
  38. has  a  user-maintained data base of "exclude"  filenames;  these  are 
  39. files  which will be excluded from the catalog if they are found on  a 
  40. disk's directory.   Typical examples of such files are COMMAND.COM and 
  41. AUTOEXEC.BAT  which are usually found on multiple diskettes and are of 
  42. no real interest to a catalog system.  The number of files that may be 
  43. cataloged  is  one  billion - a dBASE III limitation  that  we  cannot 
  44. confirm.
  45.  
  46.      The system consists of two command files:  (1) DSIDCAT.PRG is the 
  47. main driver program that handles the user interface including the main 
  48. menu,  help,  data edits and reports;  (2) DSIREAD.PRG is the heart of 
  49. the  system that takes care of reading the disk directory and  loading 
  50. the   data  bases  with  information  obtained  from  the   directory.  
  51. DSIREAD.PRG  makes  full use of dBASE III's power and is described  in 
  52. detail below. 
  53.  
  54. .cp7
  55. DATA BASES USED
  56.  
  57.      dBASE  III allows multiple data bases to be open at one time  and 
  58. the catalog program takes advantage of that.  The four data bases that 
  59. the system uses are:
  60.  
  61.  
  62. 1.  DSIFILE.DBF - data  base of cataloged filenames and  related data   
  63.     INDEX:        Indexed on FILE to DSIFILE
  64.     STRUCTURE:
  65.  
  66.       Field  Field name  Type       Width    Dec      Description
  67.       -----  ----------  ---------  -----   -----     --------------
  68.           1  FILE        Character     12             File Name
  69.           2  FBYTES      Numeric        6             Number of bytes
  70.           3  FDATE       Date           8             Creation date
  71.           4  FTIME       Character      6             Creation time
  72.           5  DISK        Character     23             Disk label
  73.           6  FCATEG      Character     30             Category
  74.           7  FDESC       Character     50             File Description
  75.       ** Total **                     136
  76.  
  77.     NOTE: FCATEG and FDESC are added by the user via the EDIT function 
  78.  
  79.  
  80. 2.  DSIDISK.DBF - data base of cataloged disks
  81.     INDEX:        Indexed on DISK to DSIDISK
  82.     STRUCTURE:
  83.  
  84.       Field  Field name  Type       Width    Dec      Description
  85.       -----  ----------  ---------  -----   -----     --------------
  86.           1  DISK        Character     23             Disk label
  87.           2  NUMFILES    Numeric        5             No. files
  88.           3  BYTESFREE   Numeric        7             Bytes free
  89.           4  BYTESUSED   Numeric        7             Bytes used
  90.       ** Total **                      43
  91.  
  92.  
  93. 3.  DSIXCLUD.DBF - data base of filenames to be excluded
  94.     INDEX:         Indexed on FILE to DSIXCLUD
  95.     STRUCTURE:
  96.  
  97.       Field  Field name  Type       Width    Dec      Description
  98.       -----  ----------  ---------  -----   -----     --------------
  99.           1  FILE        Character     12             File name
  100.       ** Total **                      13
  101.  
  102. .cp10
  103. 4.  DSISCRAT.DBF - scratch data base loaded from redirected
  104.                    output of the DOS DIR command 
  105.     INDEX:         None
  106.     STRUCTURE:
  107.  
  108.       Field  Field name  Type       Width    Dec      Description
  109.       -----  ----------  ---------  -----   -----     --------------
  110.           1  FNAME       Character      8
  111.           2  FILL1       Character      1
  112.           3  FTYPE       Character      3
  113.           4  FILL2       Character      3
  114.           5  FBYTES      Character      6
  115.           6  FILL3       Character      2
  116.           7  FDATE       Character      8
  117.           8  FILL4       Character      2
  118.           9  FTIME       Character      6
  119.       ** Total **                      40
  120.  
  121.  
  122. THE SYSTEM IN DETAIL
  123.  
  124.      Figure  1  shows  the source code for the  main  driver  program, 
  125. DSIDCAT.PRG.   The DO WHILE .F.  - ENDDO block at the beginning of the 
  126. program  shows a technique for including a cluster of comment lines in 
  127. a dBASE III program without using an asterisk on each line.  
  128.  
  129.      The  SET  SAFE OFF statement prevents dBASE III from  asking  the 
  130. user  for permission to overwrite DSISCRAT.DBF each time a new disk to 
  131. be  cataloged is read from the designated drive.   Two of  the  memory 
  132. variables  declared public are MDISK (drive where disk to be cataloged 
  133. is to be mounted) and MDIR (file to hold the redirected output of  the 
  134. DOS  DIR command).   These variables are passed to DSIREAD.PRG;  their 
  135. values may be changed by the user from a main menu option.
  136.  
  137.      The  program begins by asking the user for the  drive  containing 
  138. the system files and programs.   This allows for more than one catalog 
  139. of files to be maintained on different drives or diskettes.
  140.  
  141.      The  system's  main menu is shown in Figure  2.   I  created  the 
  142. screen  using  WordStar and then used dBASE III's dFORMAT  program  to 
  143. convert it to an FMT file.   I then used WordStar's read file  command 
  144. (^KR)  to  include the FMT file in the main  program,  DSIDCAT.PRG.  A 
  145. brief  explanation of menu choices is provided if the user  picks  the 
  146. H(elp) option. The explanation is shown in the source listing and will 
  147. not be repeated here.  However, the Z(ap) and V(iew) options introduce 
  148. new concepts and are worth discussing.
  149.  
  150.      The ZAP command of dBASE III is an efficient (and dangerous)  way 
  151. of  removing  data base records.   Its equivalent in dBASE II is  the 
  152. notoriously slow DELETE ALL and PACK commands. 
  153.  
  154.      The  V(iew)/Change  Report Destination option  assigns  either  a 
  155. space to the memory variable MPRSC if the user elects the screen to be 
  156. the report destination, or the string 'TO PRINT NOEJECT' if she elects 
  157. instead  to route the report to a printer.   With this  technique,  we 
  158. save  a lot of coding just to generate a report.   Note that under the 
  159. F)ind A File option, we only had to use the statement:
  160.  
  161.         REPO FORM DSIFILE FOR '&MFILEN'$FILE &MPRSC
  162.  
  163. instead of a more cumbersome alternative such as:
  164.  
  165.        IF PRINTER
  166.           REPO FORM DSIFILE FOR '&MFILEN'$FILE TO PRINT NOEJECT
  167.        ELSE
  168.           REPO FORM DSIFILE FOR '&MFILEN'$FILE
  169.        ENDIF
  170.  
  171.      
  172.      Another  technique  that the program uses can be seen  under  the 
  173. D(elete) a Diskname option.  In dBASE III, values of logical variables 
  174. require the surrounding periods as in .T.  or .F.  Thus, the old dBASE 
  175. II code that goes something like this:
  176.  
  177.           STORE Y TO MORE
  178.           DO WHIL MORE
  179.             ...
  180.             INPUT 'Delete another diskname? (Y/N)' TO MORE
  181.           ENDDO while more
  182.  
  183. is  fraught with danger of generating a syntax error unless  the  user 
  184. always remembers to respond with .Y. instead of just Y (or .N. instead 
  185. of  N).   We avoid that problem by replacing the INPUT statement  with 
  186. the following:
  187.  
  188.           WAIT 'Delete another diskname? (Y/N)' TO ok
  189.           STORE ok$'yY' TO more
  190.  
  191. The  last  statement  performs  the same work as  the  following  five 
  192. statements:
  193.  
  194.           IF ok$'yY'
  195.              STORE .T. TO more
  196.           ELSE
  197.              STORE .F. TO more
  198.           ENDIF
  199.  
  200.  
  201.      The  program  also  takes  advantage of  two  new  and  desirable 
  202. features in dBASE III, namely EXIT (to exit from a DO WHILE construct) 
  203. and SEEK (a superior alternative to FIND).  SEEK allows an  expression 
  204. to be its argument, so that it is completely valid to have the name of 
  205. a memory variable (instead of its value) as the argument.  We can say, 
  206. for example, 
  207.  
  208.            SEEK mvar
  209.  
  210. while we can only say something like:
  211.  
  212.            FIND &mvar
  213.  
  214.      Although  Ashton-Tate  warns  dBASE III users not to  use  macros 
  215. inside  loop  constructs such as DO-ENDDO and IF-ENDIF (the  claim  is 
  216. that  the speed of execution may be degraded up to 30 percent) we  use 
  217. macros  with impunity because we really do not have any  choice  - all 
  218. our  programs  are in one giant DO WHILE .T.  loop.   If there is  any 
  219. speed degradation, we never observed it.  To anyone who has used dBASE 
  220. II as long as we have, even a snail looks fast and, besides, dBASE III 
  221. is just light years ahead of dBASE II in speed.
  222.  
  223.      Finally,  the  program contains four statements that use the  new 
  224. SPACE  function to assign a fixed number of blanks (spaces) to  memory 
  225. variables.   The  function  saves  us  the  trouble  of  counting  (or 
  226. miscounting) spaces to assign the variables.
  227.  
  228.  
  229. HOW IT IS REALLY DONE
  230.  
  231.      The A(dd) New Disk to Catalog option of the main menu invokes the 
  232. command file, DSIREAD.PRG where all the hard work is done.   We get an 
  233. idea  of some of dBASE III's power by examining the source listing  in 
  234. Figure 3.
  235.  
  236.      dBASE III has DOS-like commands such as TYPE.  More  importantly, 
  237. it  allows us to invoke any DOS program from within it (provided  that 
  238. we  have enough memory for both dBASE and the external  program).  The 
  239. approach used by the program is to read a disk directory using the DOS 
  240. DIR  command and redirect the output of the command to a scratch  file 
  241. defined  by  the memory variable MDIR.   The actual dBASE III  command 
  242. that does this is:
  243.  
  244.         RUN DIR &mdisk.*.* >&mdir
  245.  
  246. The  period  after '&mdisk' is important because the macro is  at  the 
  247. beginning of a "word" instead of at its end.  Assuming that MDISK='B:' 
  248. and MDIR='D:DIRSCRAT.TXT', the macro expansion produces the command:
  249.  
  250.         RUN DIR B:*.* >D:DIRSCRAT.TXT
  251.  
  252.      The  program  then  decomposes the standard  output  of  the  DIR 
  253. command  into a form suitable for APPENDing to DSISCRAT.DBF.   It also 
  254. determines if the disk has a volume ID; if there is no volume ID,  the 
  255. second line will have the string 'no label'. In that case, the program 
  256. asks the user for a disk volume label and places it on the disk header 
  257. by  way  of an external program,  CLIP.COM - a public  domain  program 
  258. written  by W.C.  Bodycomb.   CLIP.COM (or a similar program  such  as 
  259. Norton's LABEL.COM) need not be on the current directory if the proper 
  260. path has been set to enable DOS to find it.
  261.  
  262.      If the volume label has been encountered before, the user has the 
  263. choice  of replacing the old entry with the current one or  continuing 
  264. with a different disk.
  265.  
  266.      The  program recognizes that a "file" is a subdirectory  when  it 
  267. encounters the string '<DIR>' in DIR's output line.  It keeps track of 
  268. all  subdirectories (up to 9 on a given disk) that it has  encountered 
  269. and reads the files of those subdirectories by invoking the CD and DIR 
  270. commands as before.
  271.  
  272.      While  the  DOS  DIR command only gives the number  of  available 
  273. bytes on the disk,  the program also computes the number of bytes that 
  274. have  been  used .   Both values are stored in the second  data  base, 
  275. DSIDISK.DBF.
  276.  
  277.      We  have  used  this system to catalog more than  4000  files  on 
  278. diskettes with multiple subdirectories.  Clearly, the best performance 
  279. is  obtained if the system files are on a hard or RAM disk.  Copies of 
  280. the entire system along with CLIP.COM are available free from the SUGI 
  281. SIG/M  RBBS  (see  below for the phone number).   You will need  a  PC 
  282. communications  program  that  support  the  XMODEM  protocol.   Those 
  283. without   one  can  get  a  starter   communications   program,   with 
  284. instructions, also from the RBBS.
  285.  
  286.  
  287.                      FIGURE 2. DSIDCAT MAIN MENU
  288.  
  289.  
  290.                           DSI dCAT MAIN MENU            Today: 07/20/84
  291. ------------------------------------------------------------------------
  292.  
  293. SETUP
  294.   S) Set Environment                     Z) Zap/Erase all catalog entries
  295.   V) View/Change report destination
  296.  
  297. DATA ENTRY/EDIT
  298.   A) Add or Read a new disk to catalog   E) Edit a filename record
  299.   D) Delete/List diskname record(s)      I) Add a filename to the EXCLUDE file
  300.  
  301. REPORTS
  302.   F) Find a filename in the catalog
  303.   L) List all files on a given disk
  304.  
  305. OTHER
  306.   H) Help with these choices
  307.   X) Exit this program
  308.  
  309.                       Please choose a letter ...  : :
  310.  
  311.  
  312.